/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"2465E853-EFA9-457F-839E-0F70F804B141"}
 */
var $pwd1 = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"87D7EA70-2A4C-4CA6-885D-B3D72149F6A5"}
 */
var $pwd2 = null;

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @private
 *
 * @properties={typeid:24,uuid:"AF086D92-975B-40FF-ADB4-B5C4D8D91882"}
 */
function ir_empresa(event) {
	
	/** @type {JSFoundSet<db:/pigeon_board/adm_t900_empresas>} */
	var fs_adm_t900_empresas = databaseManager.getFoundSet(scopes.adm_t900_empresas.$DATA_SOURCE);
	fs_adm_t900_empresas.loadRecords(foundset.getSelectedRecord().adm_t900_usuarios_to_adm_t900_empresas.adm_t900_empresas_id);
	globals.ir_formulario(event, forms.frm_adm_t900_empresas.controller.getName(), fs_adm_t900_empresas, globals.$MODO_LECTURA);
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @private
 *
 * @properties={typeid:24,uuid:"1C1ED5C2-45BB-45D0-A32E-ED53507DB84F"}
 */
function ir_perfil(event) {
	
	/** @type {JSFoundSet<db:/pigeon_board/adm_t900_perfiles>} */
	var fs_adm_t900_perfiles = databaseManager.getFoundSet(scopes.adm_t900_perfiles.$DATA_SOURCE);
	globals.ir_formulario(event, forms.frm_adm_t900_perfiles.controller.getName(), fs_adm_t900_perfiles, globals.$MODO_LECTURA);
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @private
 *
 * @properties={typeid:24,uuid:"16A10D39-BA85-40BD-9639-6BC311A5A369"}
 */
function borrar_empresa(event) {

	adm_t900_empresas_id = null;
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"BEA5442D-44E2-4CB7-8CB0-FCFE4985E420"}
 */
function borrar_perfil(event) {

	adm_t900_perfiles_id = null;
}

/**
 * @properties={typeid:24,uuid:"6F180524-CDF8-4468-9CE4-1F2B79706090"}
 */
function doEdit(){
	
	if (foundset.getSelectedRecord().isNew()){
		elements.fld_contraseña_1.visible = true;
		elements.fld_contraseña_2.visible = true;
		$pwd1 = $pwd2 = null;
	}else{
		elements.fld_contraseña_1.visible = false;
		elements.fld_contraseña_2.visible = false;
	}
	
	
	elements.btn_ir_empresa.visible = false;
	elements.btn_ir_perfil.visible = false;
	elements.btn_ir_aplicacion.visible = false;
	elements.btn_borrar_empresa.visible = true;
	elements.btn_borrar_perfil.visible = true;
	elements.btn_borrar_aplicacion.visible = true;
	
	if (foundset.getSelectedRecord().isNew()){
		if (adm_t900_empresas_id  != null){
			globals.hide_btn_reset_fields_elment(controller.getName(),elements.vlst_adm_t900_empresas_id.getName());
			controller.focusField(elements.vlst_adm_t900_perfiles_id.getName(),true);
		}
	}
}

/**
 * @properties={typeid:24,uuid:"DFF5A569-FF8B-4F4F-80EA-E26DBFDFC6F7"}
 */
function hide_btn_reset_fields(){
	
	elements.fld_contraseña_1.visible = false;
	elements.fld_contraseña_2.visible = false;
	
	elements.btn_ir_empresa.visible = true;
	elements.btn_ir_perfil.visible = true;
	elements.btn_ir_aplicacion.visible = true;
	elements.btn_borrar_empresa.visible = false;
	elements.btn_borrar_perfil.visible = false;
	elements.btn_borrar_aplicacion.visible = false;
}

/**
 * Handle changed data.
 *
 * @param {String} oldValue old value
 * @param {String} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @private
 *
 * @properties={typeid:24,uuid:"D95B56F3-CE1E-45D5-9FE8-8EBF61038E8C"}
 */
function onDataChange_b_es_super_administrador(oldValue, newValue, event) {

	if (newValue == 1){
		adm_t900_empresas_id = null;
		adm_t900_perfiles_id = null;
		b_es_adm = 0;
		elements.vlst_adm_t900_empresas_id.enabled = false;
		elements.vlst_adm_t900_perfiles_id.enabled = false;
		elements.chk_b_es_adm.enabled = false;
	}else{
		elements.vlst_adm_t900_empresas_id.enabled = true;
		elements.vlst_adm_t900_perfiles_id.enabled = true;
		elements.chk_b_es_adm.enabled = true;
	}
	return true
}

/**
 * @param {JSEvent} event
 *
 * @properties={typeid:24,uuid:"4AEA32AF-38A1-4184-8821-1D99F42418B5"}
 */
function opciones(event){
	
	var submenu_cambiar_contraseña = $menu.addMenuItem("Cambiar contraseña", cambiar_contraseña);
	submenu_cambiar_contraseña.methodArguments = [event];
	
//	var submenu_restablecer_contraseña = $menu.addMenuItem("Restablecer contraseña", restablecer_contraseña);
}

/**
 * Formulario cambio contraseña
 * @author Roberto J. Blasco
 * @version 1.0
 * @properties={typeid:24,uuid:"0ABAE605-7129-4A94-BD1C-6C8739B9E767"}
 */
function cambiar_contraseña(){
	
	forms.frm_adm_t900_usuarios_cambio_contraseña.$pwd_original = foundset.getSelectedRecord().s_md5_pwd;
	forms.frm_adm_t900_usuarios_cambio_contraseña.$pwd1 = "";
	forms.frm_adm_t900_usuarios_cambio_contraseña.$pwd2 = "";
	
	forms[globals.$frm_siv_main].elements.tab_principal.removeAllTabs();
	forms.frm_adm_t900_usuarios_cambio_contraseña.foundset.loadRecords(foundset.getSelectedRecord().adm_t900_usuarios_id);
	forms.frm_adm_t900_usuarios_cambio_contraseña._doEdit();
	forms[globals.$frm_siv_main].elements.tab_principal.addTab(forms.frm_adm_t900_usuarios_cambio_contraseña);
}

/**
 * @properties={typeid:24,uuid:"5704A0AF-F274-4E6E-A34C-D60977AFE27B"}
 */
function aceptar_antes(){
	
	if ($pwd1 == null || $pwd2 == null || $pwd1 != $pwd2){
		return false;
	}
	
	s_md5_pwd = scopes.digest.md5Hex($pwd1);
	return true;
}
